import TableLyout from '@/components/commonPublic/tableLyoutLong.vue'
import tree from "@/components/pavingRolling/tree"; //左侧机构树
import elBreadcrumb from "@/components/public/el-breadcrumb.vue";
import {
  
    getUserCompanyTreeList, //树状图
  

} from "@/api/request.js";


export default {
    name: "group",
    data() {
        return {
            name: "group",
            defaultProps: {
                children: "children",
                label: "fShortname",
            },
            treeText: {
                companyId: null,
                userId: null,
            },
            companyTree: "", //所有数据
            treeData: [], //左侧树状图数据
            // 机构树
            highlightBd: true, //左侧机构树停留背景色
            treelength: false, //左侧树显示隐藏
            // checked: true, //查看下级按钮
            showName: "未选择公司",
            checkData: [], //树状图默认选中id
            userInfo: {},
            // 列表
            getList: {
                fprojectid: "",
                fCompanyid: "", // 施工标段id
            },
            url: null,
            btnObj:[],

        };
    },
    components: {
        TableLyout,
        tree,
        elBreadcrumb,
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("GxBack-userInfo"));
      
        this.getDate()
    },
    methods: {
           // 左侧树结构
           getTree() {
            this.treeText.companyId = this.userInfo.companyId;
            this.treeText.userId = this.userInfo.userId;
            getUserCompanyTreeList(this.treeText)
                .then((res) => {
                    if (res.errcode == 0) {
                        var companyTree = res.data.userCompanyTreeList;
                        this.treeData = this.commonJs.tranListToTreeData(companyTree);
                        if (this.treeData[0].children == undefined) {
                            this.treelength = false; //左侧组织机构是否显示
                        } else {
                            this.treelength = true;
                        }

                        if (this.checkData[0]) {
                            this.showName = JSON.parse(
                                sessionStorage.getItem("GxBack-pavingRolling_treeCheck")
                            ).fShortname;
                            this.getList.fCompanyid = this.checkData[0];
                        } else {
                            this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
                            this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
                            this.checkData[0] = this.treeData[0].fCompanyid;
                        }

                        this.yj_searchForm(this.getList); // 调用主页面列表接口
                        // 列表
                    } else {
                        this.$message.error(res.msg);
                        return false;
                    }
                })
                .catch(() => {
                    return false;
                });
        },
        // 点击左侧机构树
        handleNodeClick(data) {
            this.showName = data.fShortname; //顶部显示机构名
            this.getList.fCompanyid = data.fCompanyid;
            this.getList.page = 1;
            this.getList.pageSize = 20;
            this.yj_searchForm(this.getList);
        },
        // 获取数据
        yj_searchForm(data) {
            console.log("获取列表数据", data);
          
            this.url = "http://39.99.220.82:88/layer?token=fTI4MzQ2NTIxNzE6InJ6dmciLHl5aGE6InplcmciLDc5OiJxdiIsIjg2OXIzcG9zIjoicXZhIiwiS1RXTSI6ImVyZmgie0JDUV9HVlpaSEY=&sectionId=" + data.fCompanyid + "&roadType=2";
        },

        getDate() {
            this.getTree();
            if (JSON.parse(sessionStorage.getItem("GxBack-pavingRolling_treeCheck"))) {
                var id = JSON.parse(sessionStorage.getItem("GxBack-pavingRolling_treeCheck"));
                this.checkData = [id.fCompanyid];
            }
        },
    

    },
};